home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / os2 / pc2_140.zip / SOURCE.ZIP / Source / Pc2Hook.c < prev    next >
Text File  |  1993-04-16  |  5KB  |  77 lines

  1. /***********************************************************************\
  2.  *                                PC2.c                                *
  3.  *                 Copyright (C) by Stangl Roman, 1993                 *
  4.  * This Code may be freely distributed, provided the Copyright isn't   *
  5.  * removed.                                                            *
  6.  *                                                                     *
  7.  * Pc2Hook.c    Hook the input queue to filter WM_BUTTON1(DBL)CL(IC)K  *
  8.  *              messages to allow PC2 display a Popup-Menu when mouse  *
  9.  *              button 1 is clicked on the Desktop.                    *
  10.  *                                                                     *
  11. \***********************************************************************/
  12.  
  13. static char RCSID[]="@(#) $Header: Pc2Hook.c Version 1.40 04,1993 $ (LBL)";
  14.  
  15. #define         _FILE_  "PC/2 - PC2Hook.c V1.40"
  16.  
  17. #include        "PC2.h"                 /* User include files */
  18. #include        "Error.h"
  19.  
  20. ULONG                   ulClickFlag;    /* WM_BUTTON1CLICK for a single click, and
  21.                                            WM_BUTTON1DBLCLK for a double click */
  22. HWND                    hwndDesktop;    /* DESKTOP window handle */
  23. HWND                    hwndPC2;        /* PC2 client window handle */
  24. QUERYRECFROMRECT        QueryRect;      /* Rectangle to query underlaying containers */
  25.  
  26. /*--------------------------------------------------------------------------------------*\
  27.  * This procedure saves the window handles of PC/2 main procedure for use within the    *
  28.  * DLL.                                                                                 *
  29.  * Req:                                                                                 *
  30.  *      ulC ........... Click flag (WM_BUTTON1CLICK or WM_BUTTON1DBLCLK)                *
  31.  *      hD ............ HWND of Desktop                                                 *
  32.  *      hP ............ HWND of PC/2 client window                                      *
  33.  * Returns:                                                                             *
  34.  *      none                                                                            *
  35. \*--------------------------------------------------------------------------------------*/
  36. void EXPENTRY   PC2DLL_SetHwnd(ULONG ulC, HWND hD, HWND hP)
  37. {
  38. ulClickFlag=ulC;
  39. hwndDesktop=hD;
  40. hwndPC2=hP;
  41.                                         /* Initialize to query the topmost underlaying
  42.                                            container, that is partially hit by a rectangle
  43.                                            around the pointer */
  44. QueryRect.cb=sizeof(QUERYRECFROMRECT);
  45. QueryRect.fsSearch=CMA_PARTIAL | CMA_ZORDER;
  46. }
  47.  
  48. /*--------------------------------------------------------------------------------------*\
  49.  * This procedure implements the hook of the input queue.        .                      *
  50.  * Req:                                                                                 *
  51.  *      PQMSG ......... Pointer to system QMSG structure                                *
  52.  * Returns:                                                                             *
  53.  *      FALSE ......... OS/2 should process QMSG in the normal way                      *
  54. \*--------------------------------------------------------------------------------------*/
  55. BOOL EXPENTRY   PC2DLL_Hook(HAB hab, PQMSG pqmsg, ULONG option)
  56. {
  57. if((pqmsg->hwnd==hwndDesktop) && (pqmsg->msg==ulClickFlag))
  58.     {                                   /* User clicked on Desktop with mouse button 1 */
  59.                                         /* We construct a small rectangle around the
  60.                                            current position of the pointer */
  61.     QueryRect.rect.xLeft=pqmsg->ptl.x;
  62.     QueryRect.rect.xRight=pqmsg->ptl.x+1;
  63.     QueryRect.rect.yBottom=pqmsg->ptl.y;
  64.     QueryRect.rect.yTop=pqmsg->ptl.y+1;
  65.     if(WinSendMsg(hwndDesktop, CM_QUERYRECORDFROMRECT, MPFROMLONG(CMA_FIRST), &QueryRect)==NULL)
  66.                                         /* If no container is under the rectangle of the
  67.                                            mouse pointer, we can display our Popup-Menu.
  68.                                            The type of container is unknown, but because
  69.                                            we test only on the Desktop, the should usually
  70.                                            be the icons (but not the minimized programs,
  71.                                            which are windows with a different window handle). */
  72.         WinSendMsg(hwndPC2, WM_POPUPMENU, pqmsg->mp1, pqmsg->mp2);
  73.     }
  74. return(FALSE);                          /* Process the message in the normal way */
  75. }
  76.  
  77.